package com.pioneer.gui.invoice.view;

import com.pioneer.gui.invoice.view.InvoicePanel;
import com.pioneer.gui.invoice.model.InvoiceModel;
import com.pioneer.gui.invoice.model.DropDownList;
import com.pioneer.gui.invoice.util.Constants;
import com.pioneer.gui.invoice.controller.InvoiceSelection;

import java.awt.BorderLayout;
import java.awt.GridLayout;

import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JPanel;
import javax.swing.JComboBox;
import javax.swing.ComboBoxModel;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JLabel;

import java.util.Vector;

public class InvoiceNoPanel
extends JPanel
implements Constants
{
	private final int INVOICE_DATE_LENGTH=10;
	private final int SHIP_VIA_LENGTH=5;
	private final int DATE_LENGTH=15;
	private final int STATUS_LENGTH=10;
	
	//private InvoiceModel model;
	
	public JComboBox salesmanDropDown;
	public JTextField invoiceShipVia;
		
	
	public JComboBox invoiceNo;
	public JComboBox invoiceType;
	public JTextField invoiceDate;
	public JTextField invoiceStatus;
	
	public InvoiceNoPanel(InvoiceModel model)
	{
		//this.model=invoicePanel.model;
		this.setLayout(new GridLayout(2,1));
		
		JPanel salesShipViaPanel=new JPanel(new BorderLayout());		
		
		salesmanDropDown=new JComboBox(model.getSman());		
		salesmanDropDown.addActionListener(new salesmanAdapter());		
		salesShipViaPanel.add(new LabelPanel(new JLabel("Salesperson"),salesmanDropDown),BorderLayout.CENTER);			
		invoiceShipVia = new JTextField(model.getShipVia(),null,SHIP_VIA_LENGTH);
		salesShipViaPanel.add(new LabelPanel(new JLabel("Ship Via"),invoiceShipVia),BorderLayout.EAST);		
		this.add(salesShipViaPanel);
			
		JPanel fourFieldPanel=new JPanel(new GridLayout(1,4));
		
		invoiceNo=new JComboBox(model.getInvoiceId());		
		invoiceNo.addActionListener(new InvoiceSelection(model) );
		fourFieldPanel.add(new LabelPanel(new JLabel("Invoice"),invoiceNo));		
		
		invoiceType=new JComboBox(model.getInvoiceType());
		invoiceType.addActionListener(new invoiceTypeAdapter());
		fourFieldPanel.add(new LabelPanel(new JLabel("Invoice Type"),invoiceType));		
				
		invoiceDate = new JTextField(model.getDate(),null,DATE_LENGTH);
		invoiceDate.setEditable(false);
		fourFieldPanel.add(new LabelPanel(new JLabel("Date"),invoiceDate));
				
		invoiceStatus = new JTextField(model.getEntryStatus(),null,STATUS_LENGTH);
		invoiceStatus.setEditable(false);
		fourFieldPanel.add(new LabelPanel(new JLabel("Invoice Status"),invoiceStatus));
		
		this.add(fourFieldPanel);
	}
	
	class salesmanAdapter
	implements ActionListener
	{
		public void actionPerformed(ActionEvent e)
		{
			/*
			DropDownList salesDropDown=(DropDownList)InvoiceNoPanel.this.salesmanDropDown.getModel();
			if (salesDropDown.getSelectedItem()!=null)
				InvoiceNoPanel.this.model.setSmanName(salesDropDown.getSelectedItem().toString());
			if (salesDropDown.getDatabaseKey()!=null)
			InvoiceNoPanel.this.model.setSmanId(((Integer)salesDropDown.getDatabaseKey()).intValue());
			*/
		}
	}
	
	class invoiceTypeAdapter
	implements ActionListener
	{
		public void actionPerformed(ActionEvent e)
		{
			/*
			DropDownList typesDropDown=(DropDownList)InvoiceNoPanel.this.invoiceType.getModel();
			if (typesDropDown.getSelectedItem()!=null)
				InvoiceNoPanel.this.model.setTypeDesc(typesDropDown.getSelectedItem().toString());
			if (typesDropDown.getDatabaseKey()!=null)
				InvoiceNoPanel.this.model.setType(typesDropDown.getDatabaseKey().toString());
			*/
		}
	}
}

	
